// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import FastClick from 'fastclick'
import router from './router'
import App from './App'
import tldAjax from './tld-ajax.js';
import resource from 'vue-resource';
import VueScroller from 'vue-scroller'
import VueAwesomeSwiper from 'vue-awesome-swiper';
import Vuex from 'vuex';
import 'weui/dist/style/weui.min.css'

Vue.use(VueAwesomeSwiper) //记得不要忘记这句
Vue.use(VueScroller)
Vue.use(tldAjax)
Vue.use(resource)
Vue.use(Vuex);

FastClick.attach(document.body)

var storage = window.localStorage;
storage.setItem("userId", 3)

const store = new Vuex.Store({
  state: {
    loading: false,
    isAlert: false,
    alertContent: false,
    isToast: false,
    toastContent: false
  },
  mutations: {
    updateLoading(state) {
      if (state.loading) {
        state.loading = false
      } else {
        state.loading = true
      }
    },
    updateAlert(state, content) {
      if (state.isAlert) {
        state.isAlert = false
      } else {
        state.isAlert = true
      }
      state.alertContent = content
    },
    updateToast(state, content) {
      if (state.isToast) {
        state.isToast = false
      } else {
        state.isToast = true
      }
      state.toastContent = content
    }
  }
})

Vue.config.productionTip = false

Vue.directive("longtouch", function(el, binding) {
  var oDiv = el,
    value = binding.value,
    x = 0,
    y = 0,
    z = 0,
    timer = null;
  oDiv.addEventListener("touchstart", function(e) {
    if (e.touches.length > 1) {
      return false;
    }
    z = 0;
    timer = setTimeout(function() {
      z = 1;
    }, 500);
    x = e.touches[0].clientX;
    y = e.touches[0].clientY;
    e.preventDefault();
  }, false);
  document.addEventListener("touchmove", function(e) {
    if (x != e.touches[0].clientX || y != e.touches[0].clientY) {
      clearTimeout(timer);
      return false;
    }
  }, false);
  document.addEventListener("touchend", function(ev) {
    if (z != 1) {
      clearTimeout(timer);
      x = 0;
      y = 0;
      return false;
    } else {
      x = 0;
      y = 0;
      z = 0;
      alert("长按了啊")
    }
  }, false);
})

/* eslint-disable no-new */
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app-box')
